package sas

import (
	"strings"
	"time"

	"gitee.com/micro-plat/sas/sas/modules/const/conf"
)

//ConfOption 配置选项
type ConfOption func()

var servicePrefix string

//WithServicePrefix 服务前缀
func WithServicePrefix(prefix string) ConfOption {
	return func() {
		nprefix := strings.TrimSpace(strings.Trim(prefix, "/"))
		if nprefix != "" {
			nprefix = "/" + nprefix
		}
		servicePrefix = nprefix
	}
}

func WithDBName(db string) ConfOption {
	return func() {
		conf.DBName = db
	}
}

type Option func()

func WithExpiration(expiration time.Duration) Option {
	return func() {
		conf.DefaultExpiration = expiration
	}
}

func WithCleanupInterval(interval time.Duration) Option {
	return func() {
		conf.CleanupInterval = interval
	}
}

// Config 配置
func Config(opts ...Option) {
	for _, opt := range opts {
		opt()
	}
}
